<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Hostjogja extends CI_Model {

    function login($input) {
        $this->db->where('username', $input['username']);
        $this->db->where('password', $input['password']);
        $data = $this->db->get('user');
        if ($data->num_rows == 1) {
            return $data->row();
        } else {
            return FALSE;
        }
    }

    function nama($id) {
        $this->db->where('username', $id['username']);
        $data = $this->db->get('user');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function domain() {
        $data = $this->db->get('vproduct_domain');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function hosting() {
        $data = $this->db->get('vproduct_hosting');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function sell_all() {
        $data = $this->db->get('vsell_all');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function sell_all_total() {
        $this->db->select_sum('omset');
        $data = $this->db->get('vsell_all');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function sell_domain() {
        $data = $this->db->get('vsell_domain');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function total_domain() {
        $this->db->select_sum('total');
        $data = $this->db->get('vsell_domain');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function sell_hosting() {
        $data = $this->db->get('vsell_hosting');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function total_hosting() {
        $this->db->select_sum('pemasukan');
        $data = $this->db->get('vsell_hosting');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function customer() {
        $this->db->order_by('id', 'asc');
        $data = $this->db->get('customer');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function addCus($data) {
        $this->db->insert('customer', $data);
    }

    function jenis() {
        $this->db->order_by('id', 'asc');
        $data = $this->db->get('jenis');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function nextId() {
        $data = $this->db->get('nextId');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function addInvoice($data) {
        $insert['id'] = $data['id'];
        $insert['date'] = $data['date'];
        $insert['customer_id'] = $data['customer_id'];
        $insert['username'] = $data['username'];
        $this->db->insert('invoice', $insert);
    }

    function addDetailInvoice($data) {
        $insert['invoice_id'] = $data['id'];
        $insert['jenis_id'] = $data['jenis_id'];
        $insert['qty'] = $data['qty'];
        $insert['discont'] = $data['disc'];
        $insert['status'] = $data['sts'];
        $insert['start_date'] = $data['str'];
        $insert['expire_date'] = $data['end'];
        $this->db->insert('detail_invoice', $insert);
    }

    function pengeluaran() {
        $this->db->order_by('DATE', 'asc');
        $data = $this->db->get('vpengeluaran');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function totalPengeluaran() {
        $this->db->select_sum('total');
        $data = $this->db->get('vpengeluaran');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function addNota($input) {
        $insert['no_nota'] = $input['no'];
        $insert['date'] = $input['tgl'];
        $insert['username'] = $input['petugas'];
        $this->db->insert('nota', $insert);
    }

    function addDetailNota($input) {
        $insert['nota_id'] = $input['no'];
        $insert['qty'] = $input['qty'];
        $insert['harga'] = $input['harga'];
        $insert['detail'] = $input['detail'];
        $this->db->insert('detail_nota', $insert);
    }

    function keuntungan() {
        $data = $this->db->get('vkeuntungan');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function totalKeuntungan() {
        $this->db->select_sum('paid');
        $data = $this->db->get('vkeuntungan');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function keuntunganGroup() {
        $data = $this->db->get('vkeuntungan_group');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }

    function totalKeuntunganGroup() {
        $this->db->select_sum('jumlah');
        $data = $this->db->get('vkeuntungan_group');
        if ($data->num_rows > 0) {
            return $data->result();
        }
    }
    
    function neraca(){
        $this->db->select_sum('paid');
        $income = $this->db->get('vkeuntungan');
        return $income->result();
        $this->db->select_sum('total');
        $pengeluaran = $this->db->get('vpengeluaran');
        return $pengeluaran->result();
        $data = $income[0]['paid'] - $pengeluaran[0]['total'];
        return $data->result();
    }


}

?>
